package com.binhthuan.catechist.client.data;

import com.binhthuan.catechist.shared.constant.Parameter;
import com.binhthuan.catechist.shared.constant.Service;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class AttendanceReportDS extends AbstractDS {

    private static AttendanceReportDS instance;

    private AttendanceReportDS() {
        super(Service.ATTENDANCE_LIST);

        DataSourceIntegerField id = new DataSourceIntegerField(Parameter.ID);
        id.setPrimaryKey(true);
        id.setHidden(true);

        DataSourceTextField doctrineClass = new DataSourceTextField(Parameter.COURSE);
        doctrineClass.setValueXPath(combineXPath(Parameter.COURSE, Parameter.ID));
        doctrineClass.setTypeAsDataSource(CourseDS.getInstance());

        DataSourceTextField schedule = new DataSourceTextField(Parameter.SCHEDULE);
        schedule.setValueXPath(combineXPath(Parameter.SCHEDULE, Parameter.ID));
        schedule.setTypeAsDataSource(ScheduleDS.getInstance());

        DataSourceTextField comment = new DataSourceTextField(Parameter.COMMENT);

        DataSourceDateField createTime = new DataSourceDateField(Parameter.CREATE_TIME);

        DataSourceTextField createPerson = new DataSourceTextField(Parameter.CREATE_PERSON);
        createPerson.setValueXPath(combineXPath(Parameter.CREATE_PERSON, Parameter.ID));
        createPerson.setTypeAsDataSource(TrainerDS.getInstance());

        setFields(id, doctrineClass, schedule, comment, createTime, createPerson);
    }

    public static AttendanceReportDS getInstance() {
        if (instance == null) {
            instance = new AttendanceReportDS();
        }
        return instance;
    }
}
